package com.youhome.clients.controller;

import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.service.service.HomeJunctionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chen365 on 2018/07/06.
 */
@RestController
@RequestMapping(value = "/region")
@Api(tags = "地图范围")
public class RegionController {

    @Autowired
    private HomeJunctionService homeJunctionService;

    @ApiOperation(value = "邮编范围", notes = "邮编范围", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "zip", value = "邮编", required = true, paramType = "path")
    })
    @GetMapping(value = "/zip/{zip}")
    public Object zip(@PathVariable String zip) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, homeJunctionService.selectRegionByZip(zip));
    }

    @ApiOperation(value = "城市范围", notes = "城市范围", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "city", value = "市", required = true, paramType = "path")
    })
    @GetMapping(value = "/city/{state}/{city}")
    public Object zip(@PathVariable String state, @PathVariable String city) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, homeJunctionService.selectRegionByCity(state, city));
    }
}
